//意见反馈列表
interface IopinionFeedbackListViewModel extends IBaseViewModel<IOpinionFeedQueryTerms> {
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<feedBackListResponse>;//EContract
    /**
     * 列表行高
     */
    heightA: number;
    /**
     * 时间日期格式
     */
    dateFormat: "{format:'YYYY.MM.DD HH:mm'}";

    /**
     * 反馈设备下拉
     */
    equipmentDropDown: ValueListItemResponse[];
    /**
     * 查询
     */
    queryFunc: () => void;

    /**
     * 查看详情
     */
    showFeedbackDetail: (any) => void;
}

interface IOpinionFeedQueryTerms {
    /**
     * 反馈设备
     */
    equipment: string;
    /**
     * 反馈
     */
    feedbackName: string;
    /**
     * 反馈起始时间
     */
    feedbackStartTime: string;
    /**
     * 反馈结束时间
     */
    feedbackEndTime: string;
}


class OpinionFeedListController extends ListController<IopinionFeedbackListViewModel, IOpinionFeedQueryTerms>{
    gridApi: uiGrid.IGridOptionsOf<feedBackListResponse>;//EContractListResponse

    skip: number = 0;

    constructor($scope: IopinionFeedbackListViewModel, private valueService: IValueService, private $ngBootbox: BootboxService,
        private $state: angular.ui.IStateService, private routeService: routeService, private operationService: IOperationService, private $location: ng.ILocationService) {
        super($scope);
        this.init();
    }

    /**
     * 初始化
     */
    init(): void {
        super.init();
        this.$scope.queryTerms = {
            equipment: "",
            feedbackName: "",
            feedbackStartTime: "",
            feedbackEndTime: ""
        };

        this.$scope.gridOptions = {
            multiSelect: false,//单选
            enableRowSelection: false,
            enableRowHeaderSelection: false,
            paginationPageSizes: [10, 20, 30],
            useExternalPagination: true,
            useExternalSorting: true,
            enableColumnResizing: true,
            columnDefs: [
                { displayName: "标题", field: 'title', enableColumnMenu: false, cellTooltip: true, headerTooltip: true },
                { displayName: "反馈设备", field: 'feedBackPlatform', enableColumnMenu: false, cellTooltip: true, headerTooltip: true },
                { displayName: "反馈用户名", field: 'feedBackUserName', enableColumnMenu: false, cellTooltip: true, headerTooltip: true },
                { displayName: "反馈人姓名", field: 'feedBackName', enableColumnMenu: false, cellTooltip: true, headerTooltip: true },// width: '11%'
                { displayName: '反馈时间', field: 'creationTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true },
                {
                    displayName: "操作",
                    field: 'checkmark',
                    cellTemplate:
                        '<a class="fa fa-eye m-l-xs  primary text-info" title="查看" ng-click="grid.appScope.showFeedbackDetail(row.entity)"  ></a>',//删除ng-click，添加 ui-sref="app.opera.opinion_feedbackDetail({id:row.entity.id})
                    enableColumnMenu: false, enableSorting: false
                },
            ],
            onRegisterApi: (gridApi) => {
                gridApi.pagination.on.paginationChanged(this.$scope, this.paginationChanged);
            }
        }


        $('#openStartTime').click(function () {
            $('#feedbackStartTime').datetimepicker('show');
        });
        $('#openEndTime').click(function () {
            $('#feedbackEndTime').datetimepicker('show');
        });

        this.loadEquipmentDropDown();

        this.$scope.showFeedbackDetail = this.showFeedbackDetail;

        this.query();

        //添加了意见反馈，刷新下
        this.$scope.$on('addFeedback', () => {
            this.reload();
        })
    }

    localHistory(): void {
        super.localHistory(this.$state)
    }
    getHistory(): void {
        super.getHistory(this.$state, this.$location)
    }


    /**
     * 加载数据
     */
    loadData(queryTerms: IOpinionFeedQueryTerms, skip: number, count: number): void {
        this.operationService.getOpinionList(this.queryTerms.equipment, this.queryTerms.feedbackName, this.queryTerms.feedbackStartTime,
            this.queryTerms.feedbackEndTime, skip, count).then((result) => {
                this.$scope.gridOptions.data = result.data.data;
                this.$scope.gridOptions.totalItems = result.data.total;
                // result.data.data.map((item, index) => item.index = skip++ + 1);
                this.$scope.heightA = (this.$scope.gridOptions.data.length * 39) + 96;

                if (skip == 0) {
                    this.$scope.gridOptions.paginationCurrentPage = 1;
                }
                this.$scope.querying = false;
            }, error => {
                this.$scope.querying = false;
            });
    }


    /**
     *反馈设备下拉
     */
    loadEquipmentDropDown(): void {
        this.$scope.equipmentDropDown = this.valueService.getEquipmentDropDown().data;
    }

    /**
     * 详情
     */
    showFeedbackDetail = (row) => {
        this.$state.go("app.opera.opinion_feedbackDetail", { opinionFeedBackId: row.id });
    }

}

angular.module("tms").controller("opinionFeedListController", ["$scope", "valueService", "$ngBootbox", "$state", "routeService", "operationService", "$location", OpinionFeedListController]);
